/**
* @description : 零售户详情信息
* @descriptionDetail : 零售户详情信息
* @copyright : 浙江烟草
* @author : dw
* @create : 2022-12-05 10:13:43
*/
<template>
	<view class="page">
		<!-- #ifdef H5-ONLY -->
		<theme-navbar v-if="$u.test.isEmpty(searchKeyUuid)" :is-white="false" backText="返回" title="零售户档案详情" :custom-back="goBack">
		</theme-navbar>
		<!-- #endif -->
		<!-- 内容 -->
		<view class="u-page">
			<view v-show="current == 0">
				<home-page ref="homeForm" :licenceInfo="loadcertificate"></home-page>
			</view>
			<view v-show="current == 1">
				<certificate :licenceInfo="loadcertificate"></certificate>
			</view>
			<view v-show="current == 2">
				<service :basemsg="basemsg" :licenseInfoExternal="licenseInfoExternal" :otherLicenseDetail="otherLicenseDetail"></service>
			</view>
			<view v-show="current == 3">
				<manage :manageInfo="loadcertificate"></manage>
			</view>
			<view v-show="current == 4">
				<layout :layoutInfo="loadcertificate"></layout>
			</view>
			<view v-show="current == 5">
				<people-list :retailerUuid="retailerUuid"></people-list>
			</view>
			<view v-show="current == 6">
				<visit-info :retailerUuid="retailerUuid"></visit-info>
			</view>
			<view v-show="current == 7">
				<brandDetail :retailerUuid="retailerUuid"></brandDetail>
			</view>
			<view v-show="current == 8">
				<labelDetail :licNo="licNo"></labelDetail>
			</view>
			<view v-show="current == 9">
				<regulation :retailerUuid="retailerUuid"></regulation>
			</view>
			<view v-show="current == 10">
				<illegal :illegalInfo="retailerUuid"></illegal>
			</view>
			<view v-show="current == 11">
				<association-list :retailerUuid="retailerUuid"></association-list>
			</view>
			<view v-show="current == 12">
				<outflow-message-list :retailerUuid="retailerUuid"></outflow-message-list>
			</view>
			<view v-show="current == 13">
			  <people-info :otherLicenseDetail="basemsg"></people-info>
			</view>

		</view>
		<u-tabbar :list="tabList" bg-color="#e9e9e9" :inactive-color="inactiveColor" :activeColor="activeColor" v-model="current" @change="changeTab"></u-tabbar>
	</view>
</template>

<script>
	import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
	import certificate from "./retailerItem/certificate.vue";
	import service from "./retailerItem/service.vue";
	import Manage from "./retailerItem/manage.vue";
	import Layout from "./retailerItem/layout.vue";
	import visitInfo from "@/pages/query/nolicence/detailCommon/visitInfo";
	import brandDetail from "@/pages/score/brandDetail";
	import labelDetail from "@/pages/score/labelDetail";
	import peopleList from "./retailerItem/peopleList.vue";
	import regulation from "./retailerItem/regulation.vue";
	import illegal from "./retailerItem/illegal.vue";
	import associationList from "./retailerItem/associationList.vue";
	import HomePage from "./retailerItem/homePage.vue";
	import certificateService from "@/service/certificate/certificate.service.js";
	import checkService from "@/service/check/check.service";
	import peopleInfo from './retailerItem/peopleInfo.vue'

	import {
		PATHROOT,
	} from '@/common/path.config';
	import outflowMessageList from "./retailerItem/outflowMessageList.vue";
	export default {
		components: {
			certificate,
			service,
			Manage,
			visitInfo,
			brandDetail,
			labelDetail,
			Layout,
			peopleList,
			regulation,
			illegal,
			associationList,
			HomePage,
			outflowMessageList,
			peopleInfo,
		},
		mixins: [MescrollMoreMixin, ],
		props: {
			searchKeyUuid: { // 一键搜当做组件使用
				type: String,
				default: "",
			},
		},
		data() {
			return {
				scrollTop: 0,
				inactiveColor: '#909399',
				activeColor: '#5098FF',
				current: 0,
				user: this.$storage.get(this.$rp.common.USER),
				fileRoot: PATHROOT.BASE + "/commonfile/filestore/downloadFile.do",
				fileJgUrl: PATHROOT.BASE + "/commonfile/filestore/downloadOnlineFile.do",
				retailerInfo: {},
				retailerUuid: '',
				licNo: '',
				tabList: [{
					text: '首页',
				}, {
					text: '证照',
				}, {
					text: '服务',
				}, {
					text: '经营',
				}, {
					text: '布局',
				}, {
					text: '人员',
				}, {
					text: '走访',
				}, {
					text: '品牌',
				}, {
					text: '标签',
				}, {
					text: '监管',
				}, {
					text: '违法',
				}, {
					text: '关联',
				}, {
					text: '外流',
				},{
					text: "持证",
				} ],
				tels: [],
				managementList: {}, // 经管照片
				jgImg: {},
				basemsg: {},
				recordgoods: [],
				licenseInfoExternal: {},
			};
		},
		watch: {
			searchKeyUuid: {
				handler(newVal, oldVal) {
					if (this.$u.test.isEmpty(newVal)) return;
					this.retailerUuid = this.searchKeyUuid;
					this.licNo = "";
					// 初始化实地核查图片
					this.initAuditImage();
					// 初始化经管照片
					this.initJGImage();
					this.inintRetailerInfo();
					this.getRetailerTags();
				},
				immediate: false,
			},
		},
		onLoad(options) {
			this.retailerUuid = options.retailerUuid ? options.retailerUuid : '';
			this.licNo = options.licNo ? options.licNo : '';
		},
		created() {
			if (this.searchKeyUuid) {
				// 表示从一键搜过来
				this.retailerUuid = this.searchKeyUuid;
				this.licNo = "";
			}
			// 初始化实地核查图片
			this.initAuditImage();
			// 初始化经管照片
			this.initJGImage();
		},
		mounted() {
			this.inintRetailerInfo();
			this.getRetailerTags();
			this.listBackInfo();
		},
		methods: {
			getListViewHeight() {
				let p = this.$u.sys().windowHeight - 44 - uni.upx2px(180) - this.$u.sys().statusBarHeight + 'px';
				return p;
			},
			inintRetailerInfo() {
				this.$u.loading('正在加载...');
				let param = {};
				if (!this.$u.test.isEmpty(this.retailerUuid)) {
					param.retailerUuid = this.retailerUuid;
				} else {
					param.licNo = this.licNo;
				}
				certificateService.detail(this.retailerUuid).then(res => {
					this.$u.hideLoading();
					if (res.success) {
						this.retailerInfo = res.bean;
						this.retailerUuid = this.retailerInfo.retailerUuid;

						// 布局地图点显示
						if (this.retailerInfo.longitude && this.retailerInfo.latitude) {
							this.$refs.layoutRefs.setMapInstance(this.retailerInfo);
						}
						// 专卖图片处理
						if (this.retailerInfo.storeImageUuid) {
							this.handleImage(this.retailerInfo.storeImageUuid);
						}
						if (this.retailerInfo.counterImageUuid) {
							this.handleImage(this.retailerInfo.counterImageUuid);
						}
						if (this.retailerInfo.custImageUuid) {
							this.handleImage(this.retailerInfo.custImageUuid);
						}
						if (this.retailerInfo.liceImageUuid) {
							this.handleImage(this.retailerInfo.liceImageUuid);
						}
						if (this.retailerInfo.backCounterImageUuid) {
							this.handleImage(this.retailerInfo.backCounterImageUuid);
						}
						// 获取零售户标签
						this.getRetailerTags();
					}
				}).catch(err => {
					this.$u.hideLoading();
					this.$u.toast(err);
				})
			},
			handleImage(uuid) {
				if (uuid && uuid.startsWith("20")) {
					this.$refs.homeForm.otherImage.push({
						url: this.fileRoot + "?tk=" + this.user.tk + "&fileId=" + uuid,
					});
				}
				this.$refs.homeForm.shopImageUrl = this.$refs.homeForm.otherImage[0].url;
			},
			initAuditImage() {
				certificateService.findLastFieldAuditRecord(this.retailerUuid).then(res => {
					if (!res.success) return false;
					Promise.all([
						certificateService.goFiles(res.bean, this.$FILE_GROUP_TYPE.l_audit_addr_img),
						certificateService.goFiles(res.bean, this.$FILE_GROUP_TYPE.l_audit_place_img), // 或者是 l_rlic_info_attr
						certificateService.goFiles(res.bean, this.$FILE_GROUP_TYPE.l_audit_other_img),
					]).then(dr => {
						let [addr, place, other, self, ] = [dr[0].data, dr[1].data, dr[2].data, this, ];
						let compaerData = [...addr, ...place, ...other, ];
						compaerData.length > 0 && compaerData.forEach(item => {
							item.gfiId && self.$refs.homeForm.auditImage.push({
								url: this.fileRoot + "?tk=" + this.user.tk + "&fileId=" + item.gfiId,
							});
						});
						console.log(self.$refs.homeForm.auditImage);
					});
				});
			},
			// 标签信息
			getRetailerTags() {
				let params = {
					busUuid: this.retailerUuid,
					hostCode: "R_LICENSE_INFO",
					menuCode: null,
				}
				certificateService.getRetailerDefaultTags(params).then(res => {
					this.$refs.homeForm.tags(res.data)
				}).catch(err => {
					this.$u.toast(err);
				});
			},
			initJGImage() {
				let fileSufUrl = this.fileJgUrl + "?tk=" + this.user.tk + "&fileUrl=";
				let that = this;
				certificateService.jgPlatformPicture(this.retailerUuid).then(res => {
					if (res.success) {
						that.managementList = res.data[0] || {};
						console.log(that.managementList);
						// this.jgImg = res.bean || {};
						let JgImage = [];
						that.managementList.jg_store_image && JgImage.push({
							url: fileSufUrl + encodeURIComponent(that.managementList.jg_store_image),
						});
						that.managementList.jg_counter_image && JgImage.push({
							url: fileSufUrl + encodeURIComponent(that.managementList.jg_counter_image),
						});
						that.managementList.jg_cust_image && JgImage.push({
							url: fileSufUrl + encodeURIComponent(that.managementList.jg_cust_image),
						});
						that.managementList.jg_lice_image && JgImage.push({
							url: fileSufUrl + encodeURIComponent(that.managementList.jg_lice_image),
						});
						that.managementList.jg_back_counter_image && JgImage.push({
							url: fileSufUrl + encodeURIComponent(that.managementList.jg_back_counter_image),
						});
						this.$refs.homeForm.JgImage = JgImage;
					} else {
						this.$message.error(res.msg);
					}
				}).catch(err => {
					this.$u.toast(err);
				})
			},
			listBackInfo() {
				let parms = {
					retailerUuid: this.retailerUuid,
					menuCode: null,
				}
				certificateService.getRetailcerCertificate(parms).then(res => {
					if (res.success) {
						// this.licNo = res.bean.licenseInfoPre.licNo;
						this.basemsg = res.bean.licenseInfoPre;
						if (res.bean.otherLicenseDetail) {
							this.otherLicenseDetail = res.bean.otherLicenseDetail;
						} else {
							this.otherLicenseDetail = {};
						}
						if (res.bean.licenseInfoExternal) {
							this.licenseInfoExternal = res.bean.licenseInfoExternal;
						} else {
							this.licenseInfoExternal = {};
						}

					}
				})
			},
			loadcertificate() {
				let parms = {
					retailerUuid: this.retailerUuid,
					menuCode: null,
				}
				return certificateService.getRetailcerCertificate(parms);
			},
			// 加载监管数据
			loadJGData(page) {
				let parms = {
					page: page.num,
					limit: page.size,
					retailerUuid: this.retailerUuid,
					isHaveLicense: true,
				}
				return certificateService.getRetailerCheckHis(parms);
			},
			// 加载关联数据
			loadREData(page) {
				let parms = {
					page: page.num,
					limit: page.size,
					retailerUuid: this.retailerUuid,
				}
				return certificateService.getRelRetailers(parms);
			},
			// 加载违法记录数据
			loadILData(page) {
				let parms = {
					page: page.num,
					limit: page.size,
					licNo: this.retailerUuid,
				}
				return certificateService.retailerCaseList(parms);
			},
			changeTab(index) {
				this.$u.getRect('.u-page').then(res => {
					uni.pageScrollTo({
						scrollTop: 0,
						duration: 0,
					})
				})
				this.current = index;
			},
			// 电话显示
			callPhone(e, retailerUuid) {
				this.$u.loading("查询中...");
				this.tels = [];
				checkService.retailerTels(retailerUuid).then(dr => {
					this.$u.hideLoading();
					if (dr.success) {
						let telDatas = dr.data;
						telDatas.forEach(t => {
							t.tel && this.tels.push(t.name + " " + t.tel);
						});
						uni.showActionSheet({
							itemList: this.tels,
							itemColor: "#007aff",
							success: ({
								tapIndex,
							}) => this.doPhone(this.tels[tapIndex]),
						});
					}
				});
				e.stopPropagation();
				e.preventDefault();
			},
			// 拨打电话
			doPhone(telStr) {
				let tel = telStr.substring(telStr.indexOf(" "));
				this.$deviceApi.makePhoneCall(tel);
			},
		},
	};
</script>

<style lang="scss" scoped>
	@import "style/certificate/common.scss";

	.page {
		padding: 0;
		padding-bottom: 50px;
	}

	.zk-list {
		padding: 15px 10px;

		.zk-title {
			padding-bottom: 10px;
		}

		.zk-row {
			display: flex;
			justify-content: space-between;
			color: #808080;
			line-height: 26px;
			padding: 10px 0;
		}

		.zk-desc {
			padding-bottom: 10px;
			display: inline-flex;
			width: 100%;
			color: #606266;

			.desc-tit {
				width: 86%;
			}
		}

		.zk-dir {
			display: flex;
			flex-direction: column;

			.cont-style {
				font-size: 26rpx;
				padding: 5px 0px;
				font-weight: bold;
			}

			.tit-style {
				font-size: 26rpx;
			}
		}
	}

	.re-list {
		padding: 15px 10px;
		color: #666666;
		font-size: 15px;
		border-bottom: 1px solid #E9E9E9;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		-webkit-flex-direction: row;

		.re-media {
			padding-right: 10px;
			vertical-align: middle;
		}

		.re-content {
			width: 100%;

			.re-manager {
				display: flex;
				justify-content: space-between;

				.re-title {
					font-size: 15px;
					color: #666;
					font-weight: 600;
					margin-bottom: 5px;
				}
			}

			.re-subtitle {
				padding-top: 5px;
				color: #666;
			}

			.re-icon {
				display: flex;
				padding-top: 10px;
			}
		}
	}

	.il-list {
		line-height: 24px;
		padding: 15px 10px;

		.il-row {
			display: flex;
			justify-content: space-between;
			color: #808080;
		}

		.il-title-row {
			display: flex;
			justify-content: flex-start;
			color: #808080;

			.il-50 {
				width: 50%;
			}
		}
	}

	.il-subTitle {
		color: #000;
	}

	/deep/.u-tabbar__content__item__text {
		bottom: auto;
		font-size: 14px;
	}
</style>